<template>
	<view>
		<GmapMap :center="{lat:latitude,lng:longitude}" :zoom="18" style="width: 750rpx; height: 95vh;">
			<GmapMarker :key="index" v-for="(m, index) in markersmp" :position="m.position" @click="center=m.position" />
		</GmapMap>
		<!-- <map style="width: 750rpx; height: 100vh;" id="map" :longitude="longitude" :latitude="latitude" scale="15"
			:markers="markers"></map> -->
		<view class="positop mainpadding">
			<view class="flexbetween flexrow" v-if="dataAll.status==10">
				<view class="flexleft flexrow">
					<text class="titletext lan_text bold">等待司机接单：</text>
					<text class="titletext lan_text bold">{{shijianc(time)}}</text>
				</view>
				<text class="listbtnlan" @click="modal.modalShow=true">取消订单</text>
			</view>
			<view class="flexbetween flexrow" v-if="dataAll.status==20">
				<view class="flexleft flexrow">
					<text class="titletext lan_text bold">司机已接单！</text>
				</view>
			</view>
			<view class="flexbetween flexrow" v-if="dataAll.status==30">
				<text class="titletext lan_text bold">正在前往目的地！</text>
			</view>
			<view class="flexbetween flexrow" v-if="dataAll.status==40">
				<text class="titletext lan_text bold">已到达目的地，请支付本次行程费用！</text>
			</view>
		</view>
		<moDal :message="modal" @modalSure="modalSure" @modalcancel="modalcancel"></moDal>
	</view>
	
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				latitude: "",
				longitude: "",
				markersmp: [],
				time: 0,
				jiedanTimeShow:null,
				modal: {
					modalShow: false,
					title: "是否取消订单？",
				},
				dataAll:{},
			}
		},
		onLoad() {
			// let query = window.location.search; 
			// let token = query.slice(7);
			// uni.setStorageSync("token",token)
			this.getlocation()
			this.jiedanTimeShow = setInterval(() => {
				this.getorderstate()
			}, 1000)
		},
		beforeDestroy() {
			clearInterval(this.jiedanTimeShow)
		},
		methods: {
			modalSure() {
				if (this.modal.title == "是否取消订单？") {
					httpRequest.request('/api/order/cancelOrder', 'GET', {
						id: this.dataAll.id
					}, false, false, true).then(res => {
						httpRequest.toast(res.msg);
						if (res.code == 1) {
							clearInterval(this.jiedanTimeShow)
							setTimeout(() => {
								uni.switchTab({
									url:'/pages/index/index'
								})
							}, 500)
						}
					}).catch(err => {
						httpRequest.toast(err.msg);
					})
				}
				this.modalcancel()
			},
			modalcancel() {
				this.modal.modalShow = false
			},
			getorderstate(val){
				httpRequest.request('/api/order/czOrder', 'GET', {}, false, false, true).then(res => {
					if (res.code == 0) {
						clearInterval(this.jiedanTimeShow)
						httpRequest.toast("订单已完成");
						setTimeout(() => {
							uni.switchTab({
								url:'/pages/index/index'
							})
						}, 500)
						return false
					}
					if (res.data.createtime) {
						this.time = Number(new Date()) - Number(res.data.createtime) * 1000
						this.dataAll = res.data
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			getlocation(){
				let that = this
				uni.getLocation({
					type: 'gcj02',
					geocode: true,
					success: function(res) {
						that.latitude = res.latitude
						that.longitude = res.longitude
						that.markersmp.push({position: {
							lat: res.latitude,
							lng: res.longitude,
						}})
					},
					fail(err) {
					}
				});
			},
			getmarkers(){
				let arr = []
				arr.push({
					id: 12,
					latitude: this.latitude,
					longitude: this.longitude,
					iconPath: '../../static/image/system/address.png',
					width: 40,
					height: 40,
				})
				this.markers = JSON.parse(JSON.stringify(arr))
			},
			shijianc(time) {
				let date = new Date(time)
				let Y = date.getFullYear() + '-'
				let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'
				let D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' '
				let h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':'
				let m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':'
				let s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds())
				return m + s
			},
		}
	}
</script>

<style lang="scss" scoped>
	// 注意，引入悬浮插件必须填写此样式否则会有默认样式存在
	/deep/.movable-view {
		background: none !important;
		box-shadow: none !important;
	}

	.bglan {
		background-color: #42b155;
	}

	.bai_text {
		color: #fff;
	}
	.listbtnlan{
		border: 1rpx solid #fff !important;
		color: #fff;
	}

	.margin_top6 {
		margin-top: 60rpx;
	}

	.mainpadding_top {
		padding: 30rpx;
		margin-top: 30rpx;
		box-sizing: border-box;
	}



	.itemimgBox {
		width: 170rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.listleftimg {
		width: 140rpx;
		height: 140rpx;
		min-width: 140rpx;
		position: relative;
	}

	.pdl {
		padding-bottom: 30rpx;
		/* border-bottom: 1rpx solid rgba(0, 0, 0, .03); */
		border-width: 1rpx;
		border-style: solid;
		border-top-color: #fff;
		border-left-color: #fff;
		border-right-color: #fff;
		border-bottom-color: rgba(0, 0, 0, .03);
	}

	.textcenter {
		text-align: center;
	}

	/* 提交按钮 */
	.submitbtn {
		width: 690rpx;
		background-color: #42b155;
		border-radius: 50rpx;
		text-align: center;
		color: #fff;
		padding: 20rpx 0;
	}

	.lan_text {
		color: #ffffff;
	}

	.main_size {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
	}

	.bold {
		font-weight: bold;
	}

	.margin_right {
		margin-right: 30rpx;
	}

	.flexbetween {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.flexleft {
		display: flex;
		align-items: center;
	}

	.flexright {
		display: flex;
		align-items: center;
		justify-content: flex-end;
	}

	.flexaround {
		display: flex;
		justify-content: space-around;
		align-items: center;
	}

	.ffffff {
		background-color: #fff;
	}

	.flexrow {
		flex-direction: row;
	}

	.positop {
		position: fixed;
		/* #ifdef H5 */
		top: 300rpx;
		/* #endif */
		/* #ifdef APP-PLUS || MP-WEIXIN */
		top: 130rpx;
		/* #endif */
		left: 10rpx;
		width: 730rpx;
		border-radius: 20rpx;
		background-color: #42b155;
	}

	.bottomcontent {
		border-radius: 20rpx 20rpx 0 0;
		background-color: #42b155;
	}

	.orderline {
		width: 1rpx;
		height: 20rpx;
		background-color: rgba(255, 255, 255, .6);
	}

	.payline {
		border-width: 1rpx;
		border-style: solid;
		border-top-color: rgba(255, 255, 255, .3);
		border-left-color: #42b155;
		border-right-color: #42b155;
		border-bottom-color: rgba(255, 255, 255, .3);
		padding: 30rpx 50rpx;
	}

	.listimg {
		width: 80rpx;
		height: 80rpx;
		border-radius: 50%;
	}
</style>